
#include <bur/plctypes.h>

#ifdef _DEFAULT_INCLUDES
	#include <AsDefault.h>
#endif
#include <string.h>

void _INIT ProgramInit(void)
{

	brsstrcpy((UDINT)&PlkIF, (UDINT)&"SL1.IF1");

	
	ActPage = 0;
	for(i=0; i<=1; i++)
	{
		TraceTriggerEdit[i] = 2;
	}
	TraceDataIndexEdge = 255;
	

	if(gShuttleMoveSelect[1] == 0)
	{
		for(i=1; i<=10; i++)
		{
			gShuttleMoveSelect[i] = i;
		}
	}

}



void _CYCLIC ProgramCyclic(void)
{




	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Assembly Control

	if(gAssembly.Disabled)
	{
		AssembyStatus = 0;
		AssembyStatusColour = 2 + 15*256;
	}
	else if(gAssembly.Ready)
	{
		AssembyStatus = 1;
		AssembyStatusColour = 48 + 15*256;
	}
	else if(gAssembly.Homing)
	{
		AssembyStatus = 2;
		AssembyStatusColour = 250 + 15*256;
	}
	else if(gAssembly.Stopping)
	{
		AssembyStatus = 3;
		AssembyStatusColour = 250 + 15*256;
	}
	else if(gAssembly.ErrorStop)
	{
		AssembyStatus = 4;
		AssembyStatusColour = 51 + 15*256;
	}


	
	
	
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Trace Control

	if(gCockpTrace.Configuring)
	{
		TraceStatus = 0;
		TraceStatusColour = 250 + 15*256;
	}
	else if((gCockpTrace.Active) && (gCockpTrace.WaitsOnStopEvent))
	{
		TraceStatus = 6;
		TraceStatusColour = 48 + 15*256;
	}
	else if(gCockpTrace.Active)
	{
		TraceStatus = 1;
		TraceStatusColour = 48 + 15*256;
	}
	else if(gCockpTrace.SavingData)
	{
		TraceStatus = 2;
		TraceStatusColour = 1 + 15*256;
	}
	else if(gCockpTrace.Done)
	{
		TraceStatus = 3;
		TraceStatusColour = 2 + 15*256;
	}
	else if(gCockpTrace.Error)
	{
		TraceStatus = 4;
		TraceStatusColour = 51 + 15*256;
	}
	else
	{
		TraceStatus = 5;
		TraceStatusColour = 2 + 15*256;
	}


	
	
	
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Trace Config
	
	for(i=0; i<=1; i++)
	{
		// Trigger-DataPoint edited
		// create string from single parameter
		if(TraceTriggerEdit[i] == 1)
		{
			TraceTriggerEdit[i] = 0;

			brsstrcpy((UDINT)&gCockpTracePar.StartTrigger[i].DataPointName, (UDINT)&"*Acp:");
			brsstrcat((UDINT)&gCockpTracePar.StartTrigger[i].DataPointName, (UDINT)&PlkIF);
			brsstrcat((UDINT)&gCockpTracePar.StartTrigger[i].DataPointName, (UDINT)&".ST");
			brsitoa(TraceTriggerNode[i], (UDINT)&TempString);
			brsstrcat((UDINT)&gCockpTracePar.StartTrigger[i].DataPointName, (UDINT)&TempString);
	
			brsstrcat((UDINT)&gCockpTracePar.StartTrigger[i].DataPointName, (UDINT)&"_Axis");
			brsitoa(TraceTriggerAxis[i], (UDINT)&TempString);
			brsstrcat((UDINT)&gCockpTracePar.StartTrigger[i].DataPointName, (UDINT)&TempString);
	
			brsstrcat((UDINT)&gCockpTracePar.StartTrigger[i].DataPointName, (UDINT)&":");
			brsitoa(TraceTriggerParID[i], (UDINT)&TempString);
			brsstrcat((UDINT)&gCockpTracePar.StartTrigger[i].DataPointName, (UDINT)&TempString);
		}

		// Trigger-DataPoint-Text edited
		// parse and resolve String to single parameter
		if(TraceTriggerEdit[i] == 2)
		{
			TraceTriggerEdit[i] = 0;
			
			TraceTriggerNode[i]		= 0;
			TraceTriggerAxis[i]		= 0;
			TraceTriggerParID[i]	= 0;
	
			AdrStringFound = (UDINT)&gCockpTracePar.StartTrigger[i].DataPointName;
			
			AdrStringFound = (UDINT)strstr((char*)AdrStringFound, (char*)&".ST");
			if(AdrStringFound != 0)
			{
				AdrStringFound += 3;
				TraceTriggerNode[i] = brsatoi((UDINT)AdrStringFound);
	
				AdrStringFound = (UDINT)strstr((char*)AdrStringFound, (char*)&"_Axis");
				if(AdrStringFound != 0)
				{
					AdrStringFound += 5;
					TraceTriggerAxis[i] = brsatoi((UDINT)AdrStringFound);
	
					AdrStringFound = (UDINT)strstr((char*)AdrStringFound, (char*)&":");
					if(AdrStringFound != 0)
					{
						AdrStringFound += 1;
						TraceTriggerParID[i] = brsatoi((UDINT)AdrStringFound);
					}
				}
			}
		}
	}

		
	if(TraceDataIndex > 49)		TraceDataIndex = 0;
	
	// new entry in list selected
	// parse and resolve String to single parameter
	if(TraceDataIndex != TraceDataIndexEdge)
	{
		TraceDataIndexEdge = TraceDataIndex;
		
		brsstrcpy((UDINT)&TraceDataText, (UDINT)&gCockpTracePar.DataPointName[TraceDataIndex]);
		TraceDataNode	= 0;
		TraceDataAxis	= 0;
		TraceDataParID	= 0;

		AdrStringFound = (UDINT)&TraceDataText;
		
		AdrStringFound = (UDINT)strstr((char*)AdrStringFound, (char*)&".ST");
		if(AdrStringFound != 0)
		{
			AdrStringFound += 3;
			TraceDataNode = brsatoi((UDINT)AdrStringFound);

			AdrStringFound = (UDINT)strstr((char*)AdrStringFound, (char*)&"_Axis");
			if(AdrStringFound != 0)
			{
				AdrStringFound += 5;
				TraceDataAxis = brsatoi((UDINT)AdrStringFound);

				AdrStringFound = (UDINT)strstr((char*)AdrStringFound, (char*)&":");
				if(AdrStringFound != 0)
				{
					AdrStringFound += 1;
					TraceDataParID = brsatoi((UDINT)AdrStringFound);
				}
			}
		}
	}

	// DataPoint-Parameter edited
	// create string from single parameter
	if(TraceDataEdit == 1)
	{
		TraceDataEdit = 2;
		brsstrcpy((UDINT)&TraceDataText, (UDINT)&"*Acp:");
		brsstrcat((UDINT)&TraceDataText, (UDINT)&PlkIF);
		brsstrcat((UDINT)&TraceDataText, (UDINT)&".ST");
		brsitoa(TraceDataNode, (UDINT)&TempString);
		brsstrcat((UDINT)&TraceDataText, (UDINT)&TempString);

		brsstrcat((UDINT)&TraceDataText, (UDINT)&"_Axis");
		brsitoa(TraceDataAxis, (UDINT)&TempString);
		brsstrcat((UDINT)&TraceDataText, (UDINT)&TempString);

		brsstrcat((UDINT)&TraceDataText, (UDINT)&":");
		brsitoa(TraceDataParID, (UDINT)&TempString);
		brsstrcat((UDINT)&TraceDataText, (UDINT)&TempString);
	}
	// DataPoint-Text edited
	if(TraceDataEdit == 2)
	{
		TraceDataEdit = 0;
		brsstrcpy((UDINT)&gCockpTracePar.DataPointName[TraceDataIndex], (UDINT)&TraceDataText);
		TraceDataIndexEdge = 255;	// parse and resolve string to single parameter again, if string has been edited directly
	}

	//DataPoint Insert / Delete / MoveUp / MoveDown
	if(TraceDataInsert != 0)
	{
		TraceDataInsert = 0;
		for(i=48; i>=TraceDataIndex; i--)
		{
			brsstrcpy((UDINT)&gCockpTracePar.DataPointName[i+1], (UDINT)&gCockpTracePar.DataPointName[i]);
		}
		brsstrcpy((UDINT)&gCockpTracePar.DataPointName[TraceDataIndex], (UDINT)&TraceDataText);
	}
	if(TraceDataDelete != 0)
	{
		TraceDataDelete = 0;
		for(i=TraceDataIndex; i<49; i++)
		{
			brsstrcpy((UDINT)&gCockpTracePar.DataPointName[i],	(UDINT)&gCockpTracePar.DataPointName[i+1]);
		}
		brsstrcpy((UDINT)&TraceDataText, (UDINT)&gCockpTracePar.DataPointName[TraceDataIndex]);
	}
	if((TraceDataMoveUp != 0) && (TraceDataIndex > 0))
	{
		TraceDataMoveUp = 0;
		brsstrcpy((UDINT)&TraceDataTextCopy,								(UDINT)&gCockpTracePar.DataPointName[TraceDataIndex-1]);
		brsstrcpy((UDINT)&gCockpTracePar.DataPointName[TraceDataIndex-1],	(UDINT)&gCockpTracePar.DataPointName[TraceDataIndex]);
		brsstrcpy((UDINT)&gCockpTracePar.DataPointName[TraceDataIndex],		(UDINT)&TraceDataTextCopy);
		TraceDataIndex--;
	}
	if((TraceDataMoveDn != 0) && (TraceDataIndex < 49))
	{
		TraceDataMoveDn = 0;
		brsstrcpy((UDINT)&TraceDataTextCopy,								(UDINT)&gCockpTracePar.DataPointName[TraceDataIndex+1]);
		brsstrcpy((UDINT)&gCockpTracePar.DataPointName[TraceDataIndex+1],	(UDINT)&gCockpTracePar.DataPointName[TraceDataIndex]);
		brsstrcpy((UDINT)&gCockpTracePar.DataPointName[TraceDataIndex],		(UDINT)&TraceDataTextCopy);
		TraceDataIndex++;
	}




	
	

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Movement MainPage mapping

	for(i=1; i<=10; i++)
	{
		if(gShuttleMoveSelect[i] > MAX_NUM_MOVESEQ)	gShuttleMoveSelect[i] = MAX_NUM_MOVESEQ;
		if(gShuttleMoveSelect[i] < 1)				gShuttleMoveSelect[i] = 1;
		switch(i)
		{
			 case 1:	pMoveSeqSelect1 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 2:	pMoveSeqSelect2 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 3:	pMoveSeqSelect3 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 4:	pMoveSeqSelect4 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 5:	pMoveSeqSelect5 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 6:	pMoveSeqSelect6 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 7:	pMoveSeqSelect7 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 8:	pMoveSeqSelect8 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 9:	pMoveSeqSelect9 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
			 case 10:	pMoveSeqSelect10 = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gShuttleMoveSelect[i]];		break;
		}
	}
	
	


	
	
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Movement Config

	if(MoveSeqIndex > MAX_NUM_MOVESEQ)	MoveSeqIndex = MAX_NUM_MOVESEQ;
	if(MoveSeqIndex < 1)				MoveSeqIndex = 1;
	pMoveSeq = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[MoveSeqIndex];
	
	if(MoveStepIndex > MAX_NUM_MOVESEQ_STEPS)	MoveStepIndex = MAX_NUM_MOVESEQ_STEPS;
	if(MoveStepIndex < 1)						MoveStepIndex = 1;
	pMoveStep = (ShuttleMoveSeqStep_typ*) &gShuttleMove.Sequence[MoveSeqIndex].Step[MoveStepIndex];

	for(i=1; i<=MAX_NUM_MOVESEQ; i++)
	{
		brsstrcpy((UDINT)&MoveSeqText[i], (UDINT)&gShuttleMove.Sequence[i].Label);
	}

	for(i=1; i<=MAX_NUM_MOVESEQ_STEPS; i++)
	{
		brsmemset((UDINT)&MoveStepText[i], 0, sizeof(MoveStepText[i]));
		switch(pMoveSeq->Step[i].Action)
		{
			case SEQ_NEXT_STEP:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"NEXT_STEP");
			break;
			
			case SEQ_WAIT_TIME:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"WAIT_TIME ");						brsftoa(pMoveSeq->Step[i].Time, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;	
				
			case SEQ_CHECK_TRIGGER:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"CHECK_TRIGGER Trigger:");			brsitoa(pMoveSeq->Step[i].Trigger, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Shuttle:");						brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;

			case SEQ_IF_USERDATA_EQUAL:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"IF_USERDATA_EQUAL Trigger:");		brsitoa(pMoveSeq->Step[i].Trigger, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" UserData:");						brsitoa(pMoveSeq->Step[i].UserData, (UDINT)&TempString);					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;

			case SEQ_SET_USERDATA:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"SET_USERDATA Trigger:");			brsitoa(pMoveSeq->Step[i].Trigger, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" UserData:");						brsitoa(pMoveSeq->Step[i].UserData, (UDINT)&TempString);					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;

			case SEQ_ROUTED_MOVE_VEL:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"ROUTED_MOVE_VEL Shuttle:");			brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Sector:");							brsitoa(pMoveSeq->Step[i].Sector, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Position:");						brsftoa(pMoveSeq->Step[i].Position, (UDINT)&TempString);					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" SD:");								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_POSITIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_NEGATIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_UNDEFINED)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"auto");
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" ED:");								if(pMoveSeq->Step[i].RoutedEndDirection == mcDIR_POSITIVE)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedEndDirection == mcDIR_NEGATIVE)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedEndDirection == mcDIR_UNDEFINED)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"auto");
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" EO:");								if(pMoveSeq->Step[i].RoutedShuttleOrientation == mcDIR_POSITIVE)			brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedShuttleOrientation == mcDIR_NEGATIVE)			brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedShuttleOrientation == mcDIR_UNDEFINED)			brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"auto");
			break;	
				
			case SEQ_ROUTED_MOVE_ABS:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"ROUTED_MOVE_ABS Shuttle:");			brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Sector:");							brsitoa(pMoveSeq->Step[i].Sector, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Position:");						brsftoa(pMoveSeq->Step[i].Position, (UDINT)&TempString);					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" SD:");								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_POSITIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_NEGATIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_UNDEFINED)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"auto");
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" ED:");								if(pMoveSeq->Step[i].RoutedEndDirection == mcDIR_POSITIVE)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedEndDirection == mcDIR_NEGATIVE)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedEndDirection == mcDIR_UNDEFINED)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"auto");
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" EO:");								if(pMoveSeq->Step[i].RoutedShuttleOrientation == mcDIR_POSITIVE)			brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedShuttleOrientation == mcDIR_NEGATIVE)			brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedShuttleOrientation == mcDIR_UNDEFINED)			brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"auto");
			break;
			
			case SEQ_ROUTED_MOVE_ABS_DONE:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"ROUTED_MOVE_ABS_DONE Shuttle:");	brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;
			
			case SEQ_ELASTIC_MOVE_VEL:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"ELASTIC_MOVE_VEL Shuttle:");		brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" SD:");								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_POSITIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_NEGATIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_CURRENT)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"current");
			break;	
				
			case SEQ_ELASTIC_MOVE_ADD:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"ELASTIC_MOVE_ADD Shuttle:");		brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Distance:");						brsftoa(pMoveSeq->Step[i].Position, (UDINT)&TempString);					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;	
				
			case SEQ_ELASTIC_MOVE_ABS:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"ELASTIC_MOVE_ABS Shuttle:");		brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Position:");						brsftoa(pMoveSeq->Step[i].Position, (UDINT)&TempString);					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" SD:");								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_POSITIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_NEGATIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_CURRENT)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"current");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_SHORTEST_WAY)			brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"short");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_UNDEFINED)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"auto");
			break;	
				
			case SEQ_ELASTIC_MOVE_ABS_DONE:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"ELASTIC_MOVE_ABS_DONE Shuttle:");	brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;

			case SEQ_LOCAL_MOVE_VEL:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"MOVE_VEL Shuttle:");				brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" SD:");								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_POSITIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"pos");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_NEGATIVE)				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"neg");
																								if(pMoveSeq->Step[i].RoutedStartDirection == mcDIR_CURRENT)					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"current");
			break;	
				
			case SEQ_LOCAL_MOVE_ADD:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"MOVE_ADD Shuttle:");				brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Distance:");						brsftoa(pMoveSeq->Step[i].Position, (UDINT)&TempString);					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;
					
			case SEQ_LOCAL_MOVE_ABS:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"MOVE_ABS Shuttle:");				brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Position:");						brsftoa(pMoveSeq->Step[i].Position, (UDINT)&TempString);					brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;	
				
			case SEQ_LOCAL_MOVE_ABS_DONE:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"MOVE_ABS_DONE Shuttle:");			brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;	
				
			case SEQ_CYCLIC_MOVE_VEL:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"CYCLIC_MOVE_VEL Shuttle:");			brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;	
				
			case SEQ_CYCLIC_MOVE_POS:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"CYCLIC_MOVE_POS Shuttle:");			brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;	
				
			case SEQ_CYCLIC_MOVE_POS_ELASTIC:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"CYCLIC_MOVE_POS_ELASTIC Shuttle:");	brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;
				
			case SEQ_DELETE_SHUTTLE:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"DELETE_SHUTTLE Shuttle:");			brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
			break;	
				
			case SEQ_SELECT_PARAMETER:	
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"SELECT_PARAMETER Shuttle:");		brsitoa(pMoveSeq->Step[i].Shuttle, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&" Parametersatz:");					brsftoa(pMoveSeq->Step[i].Sector, (UDINT)&TempString);						brsstrcat((UDINT)&MoveStepText[i], (UDINT)&TempString);
				break;
				
			case SEQ_SET_PARID:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"SET_PARID");
			break;
				
			case SEQ_SET_VAR:
				brsstrcat((UDINT)&MoveStepText[i], (UDINT)&"SET_VAR");
			break;
			
			default:
			break;
		}
	}

	//Step Insert / Delete / MoveUp / MoveDown
	if(MoveStepInsert != 0)
	{
		MoveStepInsert = 0;
		if(MoveStepIndex < MAX_NUM_MOVESEQ_STEPS)
		{
			for(i=(MAX_NUM_MOVESEQ_STEPS-1); i>=MoveStepIndex; i--)
			{
				brsmemcpy((UDINT)&pMoveSeq->Step[i+1], (UDINT)&pMoveSeq->Step[i],		sizeof(MoveStepCopy));
			}
		}
	}
	if(MoveStepDelete != 0)
	{
		MoveStepDelete = 0;
		if(MoveStepIndex < MAX_NUM_MOVESEQ_STEPS)
		{
			for(i=MoveStepIndex; i<MAX_NUM_MOVESEQ_STEPS; i++)
			{
				brsmemcpy((UDINT)&pMoveSeq->Step[i],	(UDINT)&pMoveSeq->Step[i+1],	sizeof(MoveStepCopy));
			}
		}
		brsmemset((UDINT)&pMoveSeq->Step[MAX_NUM_MOVESEQ_STEPS], 0, sizeof(MoveStepCopy));
	}
	if((MoveStepUp != 0) && (MoveStepIndex > 1))
	{
		MoveStepUp = 0;
		brsmemcpy((UDINT)&MoveStepCopy,						(UDINT)&pMoveSeq->Step[MoveStepIndex-1],	sizeof(MoveStepCopy));
		brsmemcpy((UDINT)&pMoveSeq->Step[MoveStepIndex-1],	(UDINT)&pMoveSeq->Step[MoveStepIndex],		sizeof(MoveStepCopy));
		brsmemcpy((UDINT)&pMoveSeq->Step[MoveStepIndex],	(UDINT)&MoveStepCopy,						sizeof(MoveStepCopy));
		MoveStepIndex--;
	}
	if((MoveStepDn != 0) && (MoveStepIndex < MAX_NUM_MOVESEQ_STEPS))
	{
		MoveStepDn = 0;
		brsmemcpy((UDINT)&MoveStepCopy,						(UDINT)&pMoveSeq->Step[MoveStepIndex+1],	sizeof(MoveStepCopy));
		brsmemcpy((UDINT)&pMoveSeq->Step[MoveStepIndex+1],	(UDINT)&pMoveSeq->Step[MoveStepIndex],		sizeof(MoveStepCopy));
		brsmemcpy((UDINT)&pMoveSeq->Step[MoveStepIndex],	(UDINT)&MoveStepCopy,						sizeof(MoveStepCopy));
		MoveStepIndex++;
	}
	




	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	pMoveSeqCalibAMR = (ShuttleMoveSeq_typ*) &gShuttleMove.Sequence[gCalibAMR.MoveSequenceIndex];

	MagSensor[0] = gCalibAMR.Sensor+0;
	MagSensor[1] = gCalibAMR.Sensor+1;
	MagSensor[2] = gCalibAMR.Sensor+2;
	MagSensor[3] = gCalibAMR.Sensor+3;
	MagSensor[4] = gCalibAMR.Sensor+4;
	pMagSens0 = (CalibAMRDataMagSens_typ*) &gCalibAMR.Data.MagSens[MagSensor[0]-1];
	pMagSens1 = (CalibAMRDataMagSens_typ*) &gCalibAMR.Data.MagSens[MagSensor[1]-1];
	pMagSens2 = (CalibAMRDataMagSens_typ*) &gCalibAMR.Data.MagSens[MagSensor[2]-1];
	pMagSens3 = (CalibAMRDataMagSens_typ*) &gCalibAMR.Data.MagSens[MagSensor[3]-1];
	pMagSens4 = (CalibAMRDataMagSens_typ*) &gCalibAMR.Data.MagSens[MagSensor[4]-1];
	
	
	




	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	if(SegmentTempVisuIxDn)
	{
		SegmentTempVisuIxDn = 0;
		SegmentTempVisuIx += 17;
	}
	if(SegmentTempVisuIxUp)
	{
		SegmentTempVisuIxUp = 0;
		if(SegmentTempVisuIx < 17)
			SegmentTempVisuIx = 0;
		else
			SegmentTempVisuIx -= 17;
	}
	if(SegmentTempVisuIx < 1)					SegmentTempVisuIx = 1;
	if(SegmentTempVisuIx > MAX_NUM_SEGMENTS)	SegmentTempVisuIx = MAX_NUM_SEGMENTS;
	gAcpTrakMaxTemp = 0.0;
	for(i=1;i<=MAX_NUM_SEGMENTS;i++)
	{
		if(gSegmentTemp[i].TEMP_BAL > gAcpTrakMaxTemp){
			gAcpTrakMaxTemp					= gSegmentTemp[i].TEMP_BAL;
		}
		brsitoa(i,									(UDINT)&SegmentTempVisu.Segment[i]);					brsmemset((UDINT)&SegmentTempVisu.Segment[i]+5			, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_CON,			(UDINT)&SegmentTempVisu.TEMP_CON[i]);					brsmemset((UDINT)&SegmentTempVisu.TEMP_CON[i]+5			, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_PROZ,			(UDINT)&SegmentTempVisu.TEMP_PROZ[i]);					brsmemset((UDINT)&SegmentTempVisu.TEMP_PROZ[i]+5		, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_AIR,			(UDINT)&SegmentTempVisu.TEMP_AIR[i]);					brsmemset((UDINT)&SegmentTempVisu.TEMP_AIR[i]+5			, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_BAL,			(UDINT)&SegmentTempVisu.TEMP_BAL[i]);					brsmemset((UDINT)&SegmentTempVisu.TEMP_BAL[i]+5			, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_CHASSIS_1,		(UDINT)&SegmentTempVisu.TEMP_CHASSIS_1[i]);				brsmemset((UDINT)&SegmentTempVisu.TEMP_CHASSIS_1[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_CHASSIS_2,		(UDINT)&SegmentTempVisu.TEMP_CHASSIS_2[i]);				brsmemset((UDINT)&SegmentTempVisu.TEMP_CHASSIS_2[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_CHASSIS_3,		(UDINT)&SegmentTempVisu.TEMP_CHASSIS_3[i]);				brsmemset((UDINT)&SegmentTempVisu.TEMP_CHASSIS_3[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS3,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS3[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS3[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS4,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS4[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS4[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS5,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS5[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS5[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS6,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS6[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS6[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS7,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS7[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS7[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS8,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS8[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS8[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS9,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS9[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS9[i]+5	, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS10,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS10[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS10[i]+5, 0, 1);
		brsftoa(gSegmentTemp[i].TEMP_POWER_SENS11,	(UDINT)&SegmentTempVisu.TEMP_POWER_SENS11[i]);			brsmemset((UDINT)&SegmentTempVisu.TEMP_POWER_SENS11[i]+5, 0, 1);
	}
	
	
		
}



void _EXIT ProgramExit(void)
{

}

